package be.jprojects.tests.filter;

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.ListModel;

public class FilteredJList extends JList {

	private FilterField filterField;
	private int DEFAULT_FIELD_WIDTH = 20;
	private JLabel filterLabel;

	public FilteredJList() {
		super();
		setCellRenderer(new FilterItemRenderer());
		setModel(new FilterModel(this));
		filterField = new FilterField(this, DEFAULT_FIELD_WIDTH);
		filterLabel = new JLabel("");
		filterLabel.setMinimumSize(new Dimension(20,20));
		//setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
	
	public void addItem(Object item) {
		((FilterModel)getModel()).addItem(item);
	}

	public void clearItems() {
		((FilterModel)getModel()).clearItems();
	}

	
	public void setModel(ListModel m) {
		super.setModel(m);
	}

	public JTextField getFilterField() {
		return filterField;
	}
	public JLabel getFilterLabel() {
		return filterLabel;
	}


	public void clear() {
		filterField.setText("");
		clearItems();
		clearSelection();
	}
	
	
}